package com.hbk.controller;

import com.hbk.base.util.PageUtil;
import com.hbk.service.IWebService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@Controller
public class WebController {

    @Resource
    private IWebService webService;

    @RequestMapping("/houtai")
    public String houtai(){
        return "redirect:/dist/index.html";
    }

    /** 获取导航的数据 */
    @ModelAttribute
    public void getNav(HttpServletRequest request){
        webService.getNav(request);
    }


    /** 首页 */
    @RequestMapping(value = {"/", "/index"})
    public String index(HttpServletRequest request){
        webService.index(request);
        return PageUtil.fromClient() + "/index";
    }



    /** 参会报名 */
    @RequestMapping("/examination")
    public String examination(HttpServletRequest request){
        webService.line(request);
        webService.examination(request);
        webService.increment(request);
        return PageUtil.fromClient() + "/examination";
    }

    /** 线路安排 */
    @RequestMapping("/line")
    public String line(HttpServletRequest request){
        webService.line(request);
        webService.examination(request);
        webService.increment(request);
        return PageUtil.fromClient() + "/line";
    }

    /** 咨询会历史 */
    @RequestMapping("/history")
    public String history(HttpServletRequest request){
        webService.line(request);
        webService.examination(request);
        webService.increment(request);
        return PageUtil.fromClient() + "/history";
    }

    /** 增值服务 */
    @RequestMapping("/increment")
    public String increment(HttpServletRequest request){
        webService.line(request);
        webService.examination(request);
        webService.increment(request);
        return PageUtil.fromClient() + "/increment";
    }

    /** 关于我们 */
    @RequestMapping("/about")
    public String about(HttpServletRequest request){
        webService.about(request);
        webService.concat(request);
        return PageUtil.fromClient() + "/about";
    }

    /** 联系我们 */
    @RequestMapping("/concat")
    public String concat(HttpServletRequest request){
        webService.about(request);
        webService.concat(request);
        return PageUtil.fromClient() + "/concat";
    }

    /** 高招资讯 */
    @RequestMapping("/recruit")
    public String recruit(HttpServletRequest request){

        return PageUtil.fromClient() + "/recruit";
    }

    /** 报考资讯 */
    @RequestMapping("/enroll")
    public String enroll(HttpServletRequest request){

        return PageUtil.fromClient() + "/enroll";
    }

    /** 新闻详情 */
    @RequestMapping("/news/{newsId}")
    public String news(@PathVariable("newsId")String newsId, HttpServletRequest request){
        boolean exist = webService.news(newsId, request);
        if(exist){
            return PageUtil.fromClient() + "/news";
        }
        return PageUtil.fromClient() + "/news404";
    }


    /** 只有新闻内部的新闻详情页面 */
    @RequestMapping("/news_content/{newsId}")
    public String news_content(@PathVariable("newsId")String newsId, HttpServletRequest request){
        boolean exist = webService.news(newsId, request);
        if(exist){
            return "/mobile/news_content";
        }
        return "/mobile/news404";
    }
}
